import {defineStore} from "pinia";

export const useTabStore = defineStore('common-tab', {
    state: () => ({
        panels: []
    }),
    getters: {
        getTab(state) {
            return () => state.panels
        },
        getIndex(state) {
            return (name) => state.panels.findIndex(item => item.name === name)
        },
        getPrevName(state) {
            return (index) => state.panels[index - 1].name
        }
    },
    actions: {
        pushTab({name, tab}) {
            if (this.panels.some(item => item.name === name)) {
                return
            }
            this.panels.push({
                name,
                tab
            })
        },
        removeTab(index) {
            this.panels.splice(index, 1)
        }
    }
})
